Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMware: Fixes Python3 compatibility of vmware_guest #55043

Closed
wants to merge 1 commit into from
Closed

VMware: Fixes Python3 compatibility of vmware_guest #55043

wants to merge 1 commit into from

Conversation

wilmardo
Copy link
Contributor

@wilmardo wilmardo commented Apr 9, 2019

SUMMARY

Fix of previous PR: #51215

This allows the code to run on Python2 and Python3. For some more background information see:
https://stackoverflow.com/questions/23175809/str-translate-gives-typeerror-translate-takes-one-argument-2-given-worked-i

This uses the helper method maketrans() which is available in Python 2(docs) and Python 3(docs):

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

vmware_guest

ADDITIONAL INFORMATION
TASK [../win-cmdb-state-sync/ : Sync virtual machine compute and network with state] *******************************************************************************************************************************************************************************************************************************************
task path: /c/Users/wilmaro/Development/Intermax/Gitlab/configuration-management/roles/win-cmdb-state-sync/tasks/vmware/guest.yml:19
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: wilmardo
<localhost> EXEC /bin/sh -c 'echo ~wilmardo && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748 `" && echo ansible-tmp-1554812000.5973012-275822956085748="` echo /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748 `" ) && sleep 0'
Using module file /c/Users/wilmaro/Development/Intermax/Gitlab/configuration-management/roles/win-cmdb-state-sync/venv/lib/python3.6/site-packages/ansible/modules/cloud/vmware/vmware_guest.py
<localhost> PUT /c/Users/wilmaro/.ansible/tmp/ansible-local-9554iow96d17/tmp2oc3e07x TO /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py
<localhost> EXEC /bin/sh -c 'chmod u+x /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/ /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py && sleep 0'
<localhost> EXEC /bin/sh -c '/c/Users/wilmaro/Development/Intermax/Gitlab/configuration-management/roles/win-cmdb-state-sync/venv/bin/python3 /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py", line 114, in <module>
    _ansiballz_main()
  File "/c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py", line 106, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py", line 49, in invoke_module
    imp.load_module('__main__', mod, module, MOD_DESC)
  File "/usr/lib/python3.6/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 170, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 618, in _exec
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py", line 2645, in <module>
  File "/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py", line 2634, in main
  File "/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py", line 2164, in deploy_vm
  File "/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py", line 1599, in customize_vm
TypeError: translate() takes exactly one argument (2 given)

fatal: [test]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py\", line 114, in <module>\n    _ansiballz_main()\n  File \"/c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py\", line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/c/Users/wilmaro/.ansible/tmp/ansible-tmp-1554812000.5973012-275822956085748/AnsiballZ_vmware_guest.py\", line 49, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/usr/lib/python3.6/imp.py\", line 235, in load_module\n    return load_source(name, filename, file)\n  File \"/usr/lib/python3.6/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 618, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py\", line 2645, in <module>\n  File \"/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py\", line 2634, in main\n  File \"/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py\", line 2164, in deploy_vm\n  File \"/tmp/ansible_vmware_guest_payload_02msqm2_/__main__.py\", line 1599, in customize_vm\nTypeError: translate() takes exactly one argument (2 given)\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

@ansibot
Copy link
Contributor

ansibot commented Apr 9, 2019

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

lib/ansible/modules/cloud/vmware/vmware_guest.py:1599:73: bad-whitespace Exactly one space required after comma             default_name = self.params['name'].translate(str.maketrans('','',string.punctuation))                                                                          ^
lib/ansible/modules/cloud/vmware/vmware_guest.py:1599:76: bad-whitespace Exactly one space required after comma             default_name = self.params['name'].translate(str.maketrans('','',string.punctuation))                                                                             ^

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

lib/ansible/modules/cloud/vmware/vmware_guest.py:1599:74: E231 missing whitespace after ','
lib/ansible/modules/cloud/vmware/vmware_guest.py:1599:77: E231 missing whitespace after ','

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Apr 9, 2019

@ansibot
Copy link
Contributor

ansibot commented Apr 9, 2019

@wilmardo, just so you are aware we have a dedicated Working Group for vmware.
You can find other people interested in this in #ansible-vmware on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. ci_verified Changes made in this PR are causing tests to fail. cloud module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. python3 small_patch support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. vmware VMware community community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 9, 2019
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 17, 2019
@ansibot
Copy link
Contributor

ansibot commented May 3, 2019

cc @goneri
click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. needs_triage Needs a first human triage before being processed. labels May 3, 2019
@wilmardo
Copy link
Contributor Author

wilmardo commented May 7, 2019

ready_for_review 🎉

Also rebased against latest devel and squashed to one commit!

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels May 7, 2019
@Akasurde Akasurde changed the title Fixes Python3 compatibility of vmware_guest VMware: Fixes Python3 compatibility of vmware_guest May 7, 2019
@goneri
Copy link
Contributor

goneri commented May 7, 2019

default_name can end-up with UTF8 caracter and I'm not sure this is expected, e.g: へヅ, but this was already like that with Python2.

@goneri
Copy link
Contributor

goneri commented May 8, 2019

shipit

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 16, 2019
@Akasurde
Copy link
Member

superseded by #54123.

@wilmardo Thanks for the contribution.

@Akasurde Akasurde closed this May 27, 2019
@ansible ansible locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. python3 small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants